/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: PageUtil
 * Author:   步步为莹
 * Date:     2019/8/17 22:28
 * Description: 分页工具类
 * History:
 */
package cn.beyond.vehicleManagement.util;

import cn.beyond.vehicleManagement.dao.BaseDao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * 〈分页工具类〉<br> 
 * 〈一句话功能简述〉
 *
 * @author 步步为莹
 * @create 2019/8/17
 * @since 1.0.0
 */
public class PageUtil extends BaseDao {
    private  static  final BaseDao dao = new BaseDao();
    /**
     *总记录数通用方法
     * @param tableName
     * @return
     */


    public  static  int getPageCount(String tableName){
        String sql="select count(1)  from "+tableName;
        ResultSet rs= dao.executeQuery(sql);
        try {
            if(rs.next()&&rs!=null){
             return  rs.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return  -1;
    }

    /**
     * 显示分页公共方法
     * @param startRow
     * @param pageCount
     * @param tableName
     * @param t
     * @param <T>
     * @return
     */
    public static   <T>List<T> getPageUtil(int startRow, int pageCount,String tableName,T t){
        String sql="select * from "+tableName+" limit ?,?";
        ResultSet rs=dao.executeQuery(sql,startRow,pageCount);
        List<T>pageList=ResultUtil.resultToList(rs,t);

     return pageList;
    }


}